package factory;

import com.zxxy.spring12.aspect;
import com.zxxy.spring12.service.impl.impl.IStudentService;
import com.zxxy.spring12.service.impl.impl.StudentService;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class MyBeanFactory {
    public static IStudentService createStudentService() {
        //1,torget class
        StudentService studentService = new StudentService();
        //2.advice
        MyAspect myAspect = new aspect.MyAspect()
        //3.weoving
        IStudentService studentServiceProxy = (IStudentService) Proxy.newProxyInstance(MyBeanFactory.class.getClassLoader(), studentService.getClass().getInterfaces(), new InvocationHandler() {
            @Override
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                Object obj = method.invoke(studentService,args);
                return obj;
            }
        });
                return studentServiceProxy;
    }
}
